/* model */
import { BaseSelectUserVuexPropertyEnum } from '@src/component/common/BaseSelectUser/store'
import { SelectUserComponentProjectTeam, SelectUserProjectTeam } from '@src/component/common/BaseSelectUser/model'

/* store */
import { useBaseSelectUserStore } from '@src/component/common/BaseSelectUser/store/hooks/base'

/* type */
import { 
  BaseSelectUserGetProjectTeamListModel
} from '@src/component/common/BaseSelectUser/types'

/* vue */
import { computed } from 'vue'

/* util */
import { isEmpty, isNotEmpty } from '@src/util/type'

/** 
 * @description 选人控件 当前查看展开的项目
*/
function useBaseSelectUserStoreCurrentToggleProjectTeam() {
  
  const store = useBaseSelectUserStore()
  
  // 当前查看展开的项目
  const currentToggleProjectTeam = computed(() => store.state.currentToggleProjectTeam)
  
  // 当前查看展开的项目是否为空
  const isCurrentToggleProjectTeamNotEmpty = computed(() => {
    return isNotEmpty(currentToggleProjectTeam.value)
  })
  
  // 当前查看展开的项目是否不为空
  const isCurrentToggleProjectTeamEmpty = computed(() => {
    return isEmpty(currentToggleProjectTeam.value)
  })
  
  const setCurrentToggleProjectTeam = (value: SelectUserProjectTeam | null = null) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetProjectCurrentToggleProjectTeam, value)
  }
  
  return {
    currentToggleProjectTeam,
    isCurrentToggleProjectTeamNotEmpty,
    isCurrentToggleProjectTeamEmpty,
    setCurrentToggleProjectTeam
  }
}

/** 
 * @description 选人控件 项目列表
*/
function useBaseSelectUserStoreProjectTeamList() {
  
  const store = useBaseSelectUserStore()
  
  // 项目列表
  const projectTeamList = computed(() => store.state.projectTeamList)
  
  // 项目列表是否为空
  const isProjectTeamListEmpty = computed(() => {
    return isEmpty(projectTeamList.value)
  })
  
  // 项目列表是否不为空
  const isProjectTeamListNotEmpty = computed(() => {
    return isNotEmpty(projectTeamList.value)
  })
  
  const setProjectTeamList = (value: SelectUserComponentProjectTeam[] = []) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetProjectTeamList, value)
  }
  
  return {
    projectTeamList,
    isProjectTeamListEmpty,
    isProjectTeamListNotEmpty,
    setProjectTeamList
  }
}

/** 
 * @description 查询选人控件的项目列表 - 默认兜底
*/
function useBaseSelectUserStoreFetchProjectTeamList() {
  
  function fetchProjectTeamList(params: BaseSelectUserGetProjectTeamListModel) {
    return (
      Promise.resolve({ success: true, data: [] })
    )
  }
  
  return fetchProjectTeamList
}


export {
  useBaseSelectUserStoreCurrentToggleProjectTeam,
  useBaseSelectUserStoreProjectTeamList,
  useBaseSelectUserStoreFetchProjectTeamList
}